package com.bird.thread.base.stopthread;

import java.util.ArrayList;
import java.util.function.Consumer;

/**
 * @author sijunqiang
 * @data 2021/6/26 11:39
 * @description: 获取主线程和子线程的名字
 */
public class ThreadName implements Runnable {

    private static ArrayList<ThreadProperties> list = new ArrayList<>(2);

    @Override
    public void run() {
        Thread thread = new Thread();
        ThreadProperties properties=new ThreadProperties(thread.getName(),thread.getId());
        list.add(properties);
    }



    public static void main(String[] args) {
        Thread thread= new Thread(new ThreadName());
        Thread thread1=new Thread();
        ThreadProperties properties2=new ThreadProperties(thread1.getName(),thread1.getId());
        list.add(properties2);

        thread.start();
    }

    private void andThen(Consumer<ThreadProperties> function1, Consumer<ThreadProperties> function2, ArrayList<ThreadProperties> list) {
        for (ThreadProperties threadProperties : list) {
            function1.andThen(function2).accept(threadProperties);
        }
    }
}

class ThreadProperties {

    private String name;

    private long id;

    public ThreadProperties(String name, long id) {
        this.name = name;
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        return sb.append("name: " + name).append(": ").append("id: ").append(id).append("\n").toString();
    }
}
